<?php

class menu_add extends SClass {

    public function process() {
        try {
            if ($this->getControlValue('ok')) {
                ServiceUtils::GetFactory()->getHmenuService()->addHmenu(
                       $this->getControlValue('name'),
                         $this->getControlValue('url'),
                        $this->getControlValue('position'),
                        $this->getControlValue('parentid')
                

                );
               
                $this->assign('message', 'ok');
           } else {
                $post = ServiceUtils::GetFactory()->getHmenuService()->getHmenuTopLevel();
                $a = array();
                while ($x = $post->getNext()) {
                    $a[] = array(
                        'id' => $x->getId(),
                        'name' => $x->getName()                        
                    );
                }
                $this->assign('postArray', $a);
                
            }
        } catch (ServiceUtils_Exception $e) {
            $this->assign('errors', $e->getErrors());
        }
    }

}